﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.Coolzon.UI.XProperty.Converters
{
    public class XHorizontalAlignmentConverter : IPropertyValueConverter
    {
        public object Convert(ConvertContext context, Metadata.ValueNode valueNode)
        {
            string strAlign = valueNode.Attributes["Value"];
            System.Windows.HorizontalAlignment horizontalAlignment = (System.Windows.HorizontalAlignment)Enum.Parse(typeof(System.Windows.HorizontalAlignment), strAlign);
            return horizontalAlignment;
        }

        public Metadata.ValueNode ConvertBack(ConvertContext context, object value)
        {
            System.Windows.HorizontalAlignment verticalAlignment = (System.Windows.HorizontalAlignment)Enum.Parse(typeof(System.Windows.HorizontalAlignment), System.Convert.ToString(value));
            Metadata.ValueNode valueNode = new Metadata.ValueNode("LegendHorizontalAlignment");
            valueNode.Attributes = new Dictionary<string, string>();
            valueNode.Attributes.Add("Value", verticalAlignment.ToString());
            return valueNode;
        }
    }
}
